﻿
using IdentityServer4.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using IdentityServer4.Services;
using static IdentityServer4.IdentityServerConstants;

namespace OAuth.Server.OAuth
{
    public class Config
    {
        // scopes define the resources in your system
        public static IEnumerable<Scope> GetScopes()
        {
            return new List<Scope>
            {
                //StandardScopes.OpenId,
                //StandardScopes.Profile,
               //StandardScopes.OfflineAccess,
                new Scope
                {
                    Name = "api1",
                    DisplayName = "API1 access",
                    Description = "My API"
                }
            };
        }

        public static IEnumerable<Client> GetClients()
        {
            return new List<Client>
            {
                  new Client
                    {
                    ClientId="auth_clientId", ClientName="authorizationCode clientId", AllowedGrantTypes=new string[]{ GrantType.AuthorizationCode},
                     ClientSecrets={
                        new Secret("secret".Sha256())
                    },
                     RedirectUris={ "https://localhost:44369/api/values/account" },
                     PostLogoutRedirectUris={ "https://localhost:44369" },
                     AuthorizationCodeLifetime=600,
                     AllowedScopes={ StandardScopes.OfflineAccess,"api"}
                }
            };
        }

        public static List<InMemoryUser> GetUsers()
        {
            return new List<InMemoryUser>
            {
                new InMemoryUser
                {
                         Subject = "1",
                    Username = "admin",
                    Password = "123",
                    Claims = new List<Claim>
                    {
                        new Claim("name", "Admin"),
                        new Claim("website", "https://admin.com")
                    }
                }
            };
        }

        public class InMemoryUser
        {
            public bool Enabled { get; set; }
            public string Subject { get; set; }
            public string Username { get; set; }
            public string Password { get; set; }
            public string Provider { get; set; }
            public string ProviderId { get; set; }
            public ICollection<Claim> Claims { get; set; }
        }
    }
}